package cn.xinfei.xdecision.engine.runner.executor.model;

import cn.xinfei.xdecision.common.model.enginex.model.RuleHitModel;
import cn.xinfei.xdecision.common.model.enginex.model.RuleSetDecisionResultData;
import cn.xinfei.xdecision.common.utils.util.JsonUtils;
import cn.xinfei.xdecision.constant.EngineResultEnum;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * 节点流转时，中间状态传递
 */
@Slf4j
public class StateTransmitModel {
    private String nextNodeCode;

    private EngineResultEnum engineResultEnum;
    /**
     * 节点输入的变量
     */
    private java.util.Map<String, Object> nodeInput = new ConcurrentHashMap<>();
    /**
     * 节点输出的变量
     */
    private Map<String, Object> nodeOutput = new ConcurrentHashMap<>();


    private CopyOnWriteArrayList<RuleHitModel> hitResultList = new CopyOnWriteArrayList<>();//命中和未命中的的规则列表，需要内部字段单独判断
    private CopyOnWriteArrayList<RuleSetDecisionResultData> branchRejectInfo = new CopyOnWriteArrayList<>();//名中分支拒绝码

    private String fail;//异常日志

    private StateTransmitModel() {
    }

    public static StateTransmitModel build() {
//        log.info("StateTransmitModel init...");
        StateTransmitModel stateTransmitModel = new StateTransmitModel();
        stateTransmitModel.setEngineResultEnum(EngineResultEnum.PROCESSING);
        return stateTransmitModel;
    }

    public String getNextNodeCode() {
        return nextNodeCode;
    }

    public StateTransmitModel setNextNodeCode(String nextNodeCode) {
        this.nextNodeCode = nextNodeCode;
        return this;
    }

    public EngineResultEnum getEngineResultEnum() {
        return engineResultEnum;
    }

    public StateTransmitModel setEngineResultEnum(EngineResultEnum engineResultEnum) {
        this.engineResultEnum = engineResultEnum;
        return this;
    }


    public Map<String, Object> getNodeInput() {
        return nodeInput;
    }

    public void setNodeInput(Map<String, Object> nodeInput) {
        this.nodeInput = nodeInput;
    }

    public Map<String, Object> getNodeOutput() {
        return nodeOutput;
    }

    public void setNodeOutput(Map<String, Object> nodeOutput) {
        this.nodeOutput = nodeOutput;
    }


    public String getFail() {
        return fail;
    }

    public void setFail(String fail) {
        this.fail = fail;
    }

    public CopyOnWriteArrayList<RuleHitModel> getHitResultList() {
        return hitResultList;
    }

    public void setHitResultList(CopyOnWriteArrayList<RuleHitModel> hitResultList) {
        this.hitResultList = hitResultList;
    }

    public CopyOnWriteArrayList<RuleSetDecisionResultData> getBranchRejectInfo() {
        return branchRejectInfo;
    }

    public void setBranchRejectInfo(CopyOnWriteArrayList<RuleSetDecisionResultData> branchRejectInfo) {
        this.branchRejectInfo = branchRejectInfo;
    }

    @Override
    public String toString() {
        return JsonUtils.toJsonString(this);
    }
}
